<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>修改用户</title>
    <link rel="stylesheet" type="text/css" media="screen" href="../../css/bootstrap.min.css">
</head>
<body>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<form class="form-horizontal" onsubmit="return false" id="form">
    <input type="hidden" id="id" name="id">
    <fieldset>
        <div class="form-group">
            <label class="col-md-2 control-label">用户名</label>
            <div class="col-md-10">
                <input class="form-control" placeholder="用户名" type="text" name="username" id="username" readonly="readonly">
            </div>
        </div>
        <div class="form-group">
            <label class="col-md-2 control-label">昵称</label>
            <div class="col-md-10">
                <input class="form-control" placeholder="昵称" type="text" name="nickname" id="nickname" maxlength="50">
            </div>
        </div>
        <!-- <div class="form-group">
            <label class="col-md-2 control-label">手机号</label>
            <div class="col-md-10">
                <input class="form-control" placeholder="手机号" type="text" maxlength="11" name="phone" id="phone">
            </div>
        </div> -->

        <div class="form-group">
            <label class="col-md-2 control-label">性别</label>
            <div class="col-md-10" style="width: 100px">
                <select class="form-control input-sm" name="sex" id="sex">
                    <option value="1">男</option>
                    <option value="0">女</option>
                </select>
            </div>
        </div>

        <div class="form-group">
            <label class="col-md-2 control-label">状态</label>
            <div class="col-md-10" style="width: 100px">
                <select class="form-control input-sm" name="enabled" id="enabled">
                    <option value="true">正常</option>
                    <option value="false">禁用</option>
                </select>
            </div>
        </div>

        <div class="form-actions">
            <div class="row" align="center">
                <div class="col-md-12">
                    <button class="btn btn-primary" onclick="location.href='userList.html'">返回</button>
                    <button class="btn btn-primary" type="submit" onclick="update()">
                        <i class="fa fa-save"></i> 保存
                    </button>
                </div>
            </div>
        </div>


    </fieldset>
</form>
</div>

<script src="../../js/constant.js"></script>
<script type="text/javascript" src="../../js/libs/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="../../js/jq.js"></script>
<script type="text/javascript" src="../../js/plugin/bootstrapvalidator/bootstrapValidator.min.js"></script>
<script type="text/javascript" src="../../js/common.js"></script>
<script type="text/javascript" src="../../layui/layui.js"></script>

<script type="text/javascript">
layui.use('layer',function(){
    var layer = layui.layer;
});
initData();
function  initData() {
    var id = getUrlParam("id");
    if(id!=""){
        $.ajax({
            type : 'get',
            url : domainName + '/api-u/users/' +id,
            async : false,
            success : function(data) {
                $("#id").val(data.id);
                $("#username").val(data.username);
                $("#nickname").val(data.nickname);
                //	$("#phone").val(data.phone);
                $("#sex").val(data.sex);
                $("#enabled").val(data.enabled+"");
            }
        });
    }
}


function update(){
    $('#form').bootstrapValidator();
    var bootstrapValidator = $("#form").data('bootstrapValidator');
    bootstrapValidator.validate();
    if(!bootstrapValidator.isValid()){
        return;
    }
    var formdata = $("#form").serializeObject();

    $.ajax({
        type: 'put',
        url: domainName + '/api-u/users',
        contentType: "application/json; charset=utf-8",
        data : JSON.stringify(formdata),
        success : function(data) {
            layer.msg("成功", {shift: -1, time: 1000}, function(){
                location.href = "userList.html";
            });
        }
    });
}
</script>
</body>
</html>